{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### API\n",
    "\n",
    "\n",
    "#### What is API\n",
    "\n",
    "API stands for **Application Programming Interface**. An API is a software intermediary that allows two applications to talk to each other.  In other words, an API is the messenger that delivers your request to the provider that you’re requesting it from and then delivers the response back to you.\n",
    "\n",
    "#### How do APIs work?\n",
    "Imagine a waiter in a restaurant.  You, the customer, are sitting at the table with a menu of choices to order from, and the kitchen is the provider who will fulfill your order.\n",
    "\n",
    "You need a link to communicate your order to the kitchen and then to deliver your food back to your table. It can’t be the chef because she’s cooking in the kitchen. You need something to connect the customer who’s ordering food and the chef who prepares it.  That’s where the **waiter** — or the **API** —  enters the picture.\n",
    "\n",
    "The waiter takes your order, delivers it to the kitchen, telling the kitchen what to do. It then delivers the response, in this case, the food, back to you. Moreover, if the API is designed correctly, hopefully, your order won’t crash!\n",
    "\n",
    "#### A real example of an API\n",
    "\n",
    "How are APIs used in the real world? Here’s a very common scenario of the API economy at work: booking a flight.\n",
    "\n",
    "When you search for flights online, you have a menu of options to choose from. You choose a departure city and date, a return city and date, cabin class, and other variables like your meal, your seat, or baggage requests.\n",
    "\n",
    "To book your flight, you need to interact with the airline’s website to access the airline’s database to see if any seats are available on those dates, and what the cost might be based on the date, flight time, route popularity, etc.\n",
    "\n",
    "You need access to that information from the airline’s database, whether you’re interacting with it from the website or an online travel service that aggregates information from multiple airlines. Alternatively, you might be accessing the information from a mobile phone. In any case, you need to get the information, and so the application must interact with the airline’s API, giving it access to the airline’s data.\n",
    "\n",
    "**APIs provide a standard way of accessing any application data, or device**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### List of API \n",
    "\n",
    "- Pandas_datareader\n",
    "- Fixer.io\n",
    "- 阿凡达云数据\n",
    "- Tushare"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Pandas_datareader\n",
    "\n",
    "#### Install \n",
    "pip install pandas-datareader\n",
    "\n",
    "#### Data Readers\n",
    "- AlphaVantage\n",
    "- Federal Reserve Economic Data (FRED)\n",
    "- Fama-French Data (Ken French’s Data Library)\n",
    "- Bank of Canada\n",
    "- Econdb\n",
    "- Enigma\n",
    "- Eurostat\n",
    "- The Investors Exchange (IEX)\n",
    "- Moscow Exchange (MOEX)\n",
    "- NASDAQ\n",
    "- Naver Finance\n",
    "- Organisation for Economic Co-operation and Development (OECD)\n",
    "- Quandl\n",
    "- Stooq.com\n",
    "- Tiingo\n",
    "- Thrift Savings Plan (TSP)\n",
    "- World Bank\n",
    "\n",
    "You may not be able to use all datasets. \n",
    "\n",
    "Please refer to its Github Repo for more details: [link here](https://pandas-datareader.readthedocs.io/en/latest/readers/index.html)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Data from FRED St.Louis"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'pandas_datareader'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-1-5c6712e1df8f>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[1;32mimport\u001b[0m \u001b[0mpandas_datareader\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mpdr\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      2\u001b[0m \u001b[0mpd\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpdr\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_data_fred\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'GS10'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      3\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mhead\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'pandas_datareader'"
     ]
    }
   ],
   "source": [
    "import pandas_datareader as pdr\n",
    "pd = pdr.get_data_fred('GS10')\n",
    "pd.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>GDP</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DATE</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2015-01-01</th>\n",
       "      <td>18003.399</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-04-01</th>\n",
       "      <td>18223.577</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-07-01</th>\n",
       "      <td>18347.425</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-10-01</th>\n",
       "      <td>18378.803</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2016-01-01</th>\n",
       "      <td>18470.156</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  GDP\n",
       "DATE                 \n",
       "2015-01-01  18003.399\n",
       "2015-04-01  18223.577\n",
       "2015-07-01  18347.425\n",
       "2015-10-01  18378.803\n",
       "2016-01-01  18470.156"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas_datareader.data as web\n",
    "import datetime\n",
    "start = datetime.datetime(2015,1,1)\n",
    "end = datetime.datetime(2020,1,1)\n",
    "gdp = web.DataReader('GDP', 'fred', start, end)\n",
    "gdp.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Data from Yahoo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Open</th>\n",
       "      <th>Close</th>\n",
       "      <th>Volume</th>\n",
       "      <th>Adj Close</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2020-10-23</th>\n",
       "      <td>116.550003</td>\n",
       "      <td>114.279999</td>\n",
       "      <td>116.389999</td>\n",
       "      <td>115.040001</td>\n",
       "      <td>82572600.0</td>\n",
       "      <td>115.040001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-10-26</th>\n",
       "      <td>116.550003</td>\n",
       "      <td>112.879997</td>\n",
       "      <td>114.010002</td>\n",
       "      <td>115.050003</td>\n",
       "      <td>111850700.0</td>\n",
       "      <td>115.050003</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-10-27</th>\n",
       "      <td>117.279999</td>\n",
       "      <td>114.540001</td>\n",
       "      <td>115.489998</td>\n",
       "      <td>116.599998</td>\n",
       "      <td>92276800.0</td>\n",
       "      <td>116.599998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-10-28</th>\n",
       "      <td>115.430000</td>\n",
       "      <td>111.099998</td>\n",
       "      <td>115.050003</td>\n",
       "      <td>111.199997</td>\n",
       "      <td>143525000.0</td>\n",
       "      <td>111.199997</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-10-29</th>\n",
       "      <td>115.328499</td>\n",
       "      <td>112.279999</td>\n",
       "      <td>112.370003</td>\n",
       "      <td>115.143997</td>\n",
       "      <td>61523716.0</td>\n",
       "      <td>115.143997</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  High         Low        Open       Close       Volume  \\\n",
       "Date                                                                      \n",
       "2020-10-23  116.550003  114.279999  116.389999  115.040001   82572600.0   \n",
       "2020-10-26  116.550003  112.879997  114.010002  115.050003  111850700.0   \n",
       "2020-10-27  117.279999  114.540001  115.489998  116.599998   92276800.0   \n",
       "2020-10-28  115.430000  111.099998  115.050003  111.199997  143525000.0   \n",
       "2020-10-29  115.328499  112.279999  112.370003  115.143997   61523716.0   \n",
       "\n",
       "             Adj Close  \n",
       "Date                    \n",
       "2020-10-23  115.040001  \n",
       "2020-10-26  115.050003  \n",
       "2020-10-27  116.599998  \n",
       "2020-10-28  111.199997  \n",
       "2020-10-29  115.143997  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Get data from Yahoo\n",
    "import pandas_datareader.data as web\n",
    "import datetime\n",
    "start = datetime.datetime(2019, 1, 1) # or start = '1/1/2016'\n",
    "end = datetime.date.today()\n",
    "prices = web.DataReader('AAPL', 'yahoo', start, end)\n",
    "prices.tail()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 有用的命令 requests\n",
    "\n",
    "The requests module allows you to send HTTP requests using Python.\n",
    "\n",
    "The HTTP request returns a `Response Object` with all the response data (content, encoding, status, etc).\n",
    "\n",
    "\n",
    "Detail: https://www.w3schools.com/python/module_requests.asp"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### JSON\n",
    "\n",
    "JSON(JavaScript Object Notation, JS 对象简谱) 是一种轻量级的数据交换格式。它基于 ECMAScript (欧洲计算机协会制定的js规范)的一个子集，采用完全独立于编程语言的文本格式来存储和表示数据。简洁和清晰的层次结构使得 JSON 成为理想的数据交换语言。 易于人阅读和编写，同时也易于机器解析和生成，并有效地提升网络传输效率。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Fixer.io\n",
    "\n",
    "Powered by 15+ exchange rate data sources, the Fixer API is capable of delivering real-time exchange rate data for 170 world currencies. The API comes with multiple endpoints, each serving a different use case. Endpoint functionalities include getting the latest exchange rate data for all or a specific set of currencies, converting amounts from one currency to another, retrieving Time-Series data for one or multiple currencies and querying the API for daily fluctuation data.\n",
    "\n",
    "https://fixer.io/quickstart\n",
    "\n",
    "You need to sign in and get an access key to kick off "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Please input a date with a proper format YYYY-MM-DD: 2020-11-01\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Exchange Rate on 2020-11-01:\n",
      "1 USD = 1.164151 EUR\n",
      "1 AUD = 1.661196 EUR\n",
      "1 CAD = 1.556098 EUR\n",
      "1 CNY = 7.789568 EUR\n",
      "1 CHF = 1.067789 EUR\n",
      "1 GBP = 0.900541 EUR\n",
      "1 HKD = 9.025489 EUR\n"
     ]
    }
   ],
   "source": [
    "def get_fixer_hist(date, symbols = 'USD,AUD,CAD,CNY,CHF,GBP,HKD'):\n",
    "    import requests\n",
    "    import json\n",
    "    # get the data from Fixer.io the \n",
    "    # You need to sign in to obtain a free access_key \n",
    "    access_key = '0287efab831449699ce8333ec5307d00'\n",
    "    root_url = 'http://data.fixer.io/api/'\n",
    "    # Make the URL\n",
    "    url = root_url + date +'?'+ 'access_key='+ access_key + '&symbols=' + symbols + '&format=1'\n",
    "    # Creat a header\n",
    "    headers = {'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.133 Safari/534.16'}\n",
    "    # request data from API\n",
    "    res = requests.get(url, headers = headers)\n",
    "    # Get content, in case of Chinese we need to encode\n",
    "    content = res.text\n",
    "    # Load JSON data\n",
    "    dcon = json.loads(content)\n",
    "    return dcon['date'], dcon['rates'], url\n",
    "\n",
    "dat = input('Please input a date with a proper format YYYY-MM-DD:')\n",
    "date, rates, url = get_fixer_hist(dat)\n",
    "print('Exchange Rate on {}:'.format(date))\n",
    "for key,values in rates.items():\n",
    "    print('1 '+ key +' = '+ str(values) +' EUR')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 阿凡达云数据平台\n",
    "\n",
    "http://api.avatardata.cn/ActNews/Query?key=3c901762cd104a2793df344b6015ff00&keyword="
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def avatardata(keyword):\n",
    "    import requests\n",
    "    import json\n",
    "    \n",
    "    access_key = '3c901762cd104a2793df344b6015ff00'\n",
    "    root_url = 'http://api.avatardata.cn/ActNews/Query?'\n",
    "    url = root_url + 'key=' + access_key + '&keyword=' + keyword\n",
    "    headers = {'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.133 Safari/534.16'}\n",
    "    # request data from API\n",
    "    res = requests.get(url, headers = headers)\n",
    "    # Get content, in case of Chinese we need to encode\n",
    "    content = res.text\n",
    "    # Load JSON data\n",
    "    dcon = json.loads(content)\n",
    "    return dcon['result'], url\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "想听谁的八卦: 特朗普\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "特朗普卸任后推特发文将不再受保护  2020-11-09 08:02:37\n",
      "特朗普发推:什么时候由媒体来宣布下任总统了?  2020-11-09 08:15:00\n",
      "特朗普再发推特风暴!援引前众议长和法律分析师 特朗普称许多证词显示存在...  2020-11-09 07:23:32\n",
      "特朗普愤愤不平不想承认败选发推文:何时由媒体宣布下任总统?但,美国大选...  2020-11-09 08:36:49\n"
     ]
    }
   ],
   "source": [
    "keyword = input('想听谁的八卦:')\n",
    "res, url = avatardata(keyword)\n",
    "\n",
    "for r in res:\n",
    "    print(r['full_title'] +'  '+ r['pdate_src'] ) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Tushare\n",
    "\n",
    "tushare.pro \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Please input the token：   ························································\n"
     ]
    }
   ],
   "source": [
    "import tushare as ts\n",
    "import getpass\n",
    "\n",
    "tushare_token = getpass.getpass(\"Please input the token：  \")\n",
    "pro = ts.pro_api(tushare_token)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>shortname</th>\n",
       "      <th>province</th>\n",
       "      <th>city</th>\n",
       "      <th>address</th>\n",
       "      <th>phone</th>\n",
       "      <th>office</th>\n",
       "      <th>website</th>\n",
       "      <th>chairman</th>\n",
       "      <th>manager</th>\n",
       "      <th>reg_capital</th>\n",
       "      <th>setup_date</th>\n",
       "      <th>end_date</th>\n",
       "      <th>employees</th>\n",
       "      <th>main_business</th>\n",
       "      <th>org_code</th>\n",
       "      <th>credit_code</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>北京广能投资基金管理有限公司</td>\n",
       "      <td>广能基金</td>\n",
       "      <td>北京</td>\n",
       "      <td>北京市</td>\n",
       "      <td>北京市朝阳区北四环中路27号院5号楼2712-2715A</td>\n",
       "      <td>None</td>\n",
       "      <td>北京市朝阳区北四环中路27号院5号楼2712-2715A</td>\n",
       "      <td>www.gnfund.cn</td>\n",
       "      <td>刘锡潜</td>\n",
       "      <td>杨运成</td>\n",
       "      <td>10000.0000</td>\n",
       "      <td>20111031</td>\n",
       "      <td>None</td>\n",
       "      <td>10.0</td>\n",
       "      <td>None</td>\n",
       "      <td>584419680</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>宏源证券股份有限公司</td>\n",
       "      <td>宏源证券</td>\n",
       "      <td>新疆</td>\n",
       "      <td>乌鲁木齐市</td>\n",
       "      <td>新疆维吾尔自治区乌鲁木齐市文艺路233号宏源大厦</td>\n",
       "      <td>86-991-2301870</td>\n",
       "      <td>新疆维吾尔自治区乌鲁木齐市文艺路233号宏源大厦</td>\n",
       "      <td>www.hysec.com</td>\n",
       "      <td>冯戎</td>\n",
       "      <td>冯戎</td>\n",
       "      <td>397240.8332</td>\n",
       "      <td>19930525</td>\n",
       "      <td>None</td>\n",
       "      <td>5347.0</td>\n",
       "      <td>主要业务:代理买卖证券.</td>\n",
       "      <td>228593068</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>国元证券股份有限公司</td>\n",
       "      <td>国元证券</td>\n",
       "      <td>安徽</td>\n",
       "      <td>合肥市</td>\n",
       "      <td>安徽省合肥市梅山路18号</td>\n",
       "      <td>86-551-62207323,86-551-62207968</td>\n",
       "      <td>安徽省合肥市梅山路18号</td>\n",
       "      <td>www.gyzq.com.cn</td>\n",
       "      <td>蔡咏</td>\n",
       "      <td>俞仕新</td>\n",
       "      <td>336544.7047</td>\n",
       "      <td>19970606</td>\n",
       "      <td>None</td>\n",
       "      <td>3330.0</td>\n",
       "      <td>主营业务:经纪业务,自营投资业务,投行业务,资产管理业务,基金管理业务,期货业务,境外业务国...</td>\n",
       "      <td>731686376</td>\n",
       "      <td>91340000731686376P</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>广发证券股份有限公司</td>\n",
       "      <td>广发证券</td>\n",
       "      <td>广东</td>\n",
       "      <td>广州市</td>\n",
       "      <td>广东省广州市黄埔区中新广州知识城腾飞一街2号618室</td>\n",
       "      <td>86-20-87555888,86-20-87550565,86-20-87550265</td>\n",
       "      <td>广东省广州市天河区天河北路183-187号大都会广场40楼5楼,7楼,8楼,18楼,19楼,...</td>\n",
       "      <td>www.gf.com.cn</td>\n",
       "      <td>孙树明</td>\n",
       "      <td>林治海</td>\n",
       "      <td>762108.7664</td>\n",
       "      <td>19940121</td>\n",
       "      <td>None</td>\n",
       "      <td>12103.0</td>\n",
       "      <td>主营业务:证券经纪</td>\n",
       "      <td>126335439</td>\n",
       "      <td>91440000126335439C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>长江证券股份有限公司</td>\n",
       "      <td>长江证券</td>\n",
       "      <td>湖北</td>\n",
       "      <td>武汉市</td>\n",
       "      <td>湖北省武汉市江汉区新华路特8号</td>\n",
       "      <td>86-27-65799866,86-27-65799856</td>\n",
       "      <td>湖北省武汉市江汉区新华路特8号</td>\n",
       "      <td>www.cjsc.com</td>\n",
       "      <td>尤习贵</td>\n",
       "      <td>刘元瑞</td>\n",
       "      <td>552947.0960</td>\n",
       "      <td>19970724</td>\n",
       "      <td>None</td>\n",
       "      <td>6637.0</td>\n",
       "      <td>主营业务:证券经纪</td>\n",
       "      <td>700821272</td>\n",
       "      <td>91420000700821272A</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             name shortname province   city                       address  \\\n",
       "0  北京广能投资基金管理有限公司      广能基金       北京    北京市  北京市朝阳区北四环中路27号院5号楼2712-2715A   \n",
       "1      宏源证券股份有限公司      宏源证券       新疆  乌鲁木齐市      新疆维吾尔自治区乌鲁木齐市文艺路233号宏源大厦   \n",
       "2      国元证券股份有限公司      国元证券       安徽    合肥市                  安徽省合肥市梅山路18号   \n",
       "3      广发证券股份有限公司      广发证券       广东    广州市    广东省广州市黄埔区中新广州知识城腾飞一街2号618室   \n",
       "4      长江证券股份有限公司      长江证券       湖北    武汉市               湖北省武汉市江汉区新华路特8号   \n",
       "\n",
       "                                          phone  \\\n",
       "0                                          None   \n",
       "1                                86-991-2301870   \n",
       "2               86-551-62207323,86-551-62207968   \n",
       "3  86-20-87555888,86-20-87550565,86-20-87550265   \n",
       "4                 86-27-65799866,86-27-65799856   \n",
       "\n",
       "                                              office          website  \\\n",
       "0                       北京市朝阳区北四环中路27号院5号楼2712-2715A    www.gnfund.cn   \n",
       "1                           新疆维吾尔自治区乌鲁木齐市文艺路233号宏源大厦    www.hysec.com   \n",
       "2                                       安徽省合肥市梅山路18号  www.gyzq.com.cn   \n",
       "3  广东省广州市天河区天河北路183-187号大都会广场40楼5楼,7楼,8楼,18楼,19楼,...    www.gf.com.cn   \n",
       "4                                    湖北省武汉市江汉区新华路特8号     www.cjsc.com   \n",
       "\n",
       "  chairman manager  reg_capital setup_date end_date  employees  \\\n",
       "0      刘锡潜     杨运成   10000.0000   20111031     None       10.0   \n",
       "1       冯戎      冯戎  397240.8332   19930525     None     5347.0   \n",
       "2       蔡咏     俞仕新  336544.7047   19970606     None     3330.0   \n",
       "3      孙树明     林治海  762108.7664   19940121     None    12103.0   \n",
       "4      尤习贵     刘元瑞  552947.0960   19970724     None     6637.0   \n",
       "\n",
       "                                       main_business   org_code  \\\n",
       "0                                               None  584419680   \n",
       "1                                       主要业务:代理买卖证券.  228593068   \n",
       "2  主营业务:经纪业务,自营投资业务,投行业务,资产管理业务,基金管理业务,期货业务,境外业务国...  731686376   \n",
       "3                                          主营业务:证券经纪  126335439   \n",
       "4                                          主营业务:证券经纪  700821272   \n",
       "\n",
       "          credit_code  \n",
       "0                None  \n",
       "1                None  \n",
       "2  91340000731686376P  \n",
       "3  91440000126335439C  \n",
       "4  91420000700821272A  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pro.fund_company()\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ts_code</th>\n",
       "      <th>chairman</th>\n",
       "      <th>manager</th>\n",
       "      <th>secretary</th>\n",
       "      <th>setup_date</th>\n",
       "      <th>province</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>002676.SZ</td>\n",
       "      <td>莫绮颜</td>\n",
       "      <td>莫绮颜</td>\n",
       "      <td>李笛鸣</td>\n",
       "      <td>19920508</td>\n",
       "      <td>广东</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>002875.SZ</td>\n",
       "      <td>曹璋</td>\n",
       "      <td>曹璋</td>\n",
       "      <td>王峰</td>\n",
       "      <td>20010920</td>\n",
       "      <td>广东</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>300664.SZ</td>\n",
       "      <td>王鹏鹞</td>\n",
       "      <td>王鹏鹞</td>\n",
       "      <td>夏淑芬</td>\n",
       "      <td>19970715</td>\n",
       "      <td>江苏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>002564.SZ</td>\n",
       "      <td>俞铮庆</td>\n",
       "      <td>俞铮庆</td>\n",
       "      <td>王煜</td>\n",
       "      <td>20010331</td>\n",
       "      <td>江苏</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>300943.SZ</td>\n",
       "      <td>杨广宇</td>\n",
       "      <td>梁柏松</td>\n",
       "      <td>陈峰</td>\n",
       "      <td>19930508</td>\n",
       "      <td>浙江</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ts_code chairman manager secretary setup_date province\n",
       "0  002676.SZ      莫绮颜     莫绮颜       李笛鸣   19920508       广东\n",
       "1  002875.SZ       曹璋      曹璋        王峰   20010920       广东\n",
       "2  300664.SZ      王鹏鹞     王鹏鹞       夏淑芬   19970715       江苏\n",
       "3  002564.SZ      俞铮庆     俞铮庆        王煜   20010331       江苏\n",
       "4  300943.SZ      杨广宇     梁柏松        陈峰   19930508       浙江"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pro.stock_company(exchange='SZSE', fields='ts_code,chairman,manager,secretary,setup_date,province')\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>publish_date</th>\n",
       "      <th>country</th>\n",
       "      <th>confirmed_num</th>\n",
       "      <th>update_time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>272</th>\n",
       "      <td>20200203</td>\n",
       "      <td>美国</td>\n",
       "      <td>9</td>\n",
       "      <td>2020-02-03 09:28:34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>273</th>\n",
       "      <td>20200202</td>\n",
       "      <td>美国</td>\n",
       "      <td>8</td>\n",
       "      <td>2020-02-02 07:41:43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>274</th>\n",
       "      <td>20200201</td>\n",
       "      <td>美国</td>\n",
       "      <td>6</td>\n",
       "      <td>2020-02-01 02:48:13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>275</th>\n",
       "      <td>20200131</td>\n",
       "      <td>美国</td>\n",
       "      <td>6</td>\n",
       "      <td>2020-01-31 07:17:36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>276</th>\n",
       "      <td>20200127</td>\n",
       "      <td>美国</td>\n",
       "      <td>5</td>\n",
       "      <td>2020-01-27 17:20:43</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    publish_date country  confirmed_num          update_time\n",
       "272     20200203      美国              9  2020-02-03 09:28:34\n",
       "273     20200202      美国              8  2020-02-02 07:41:43\n",
       "274     20200201      美国              6  2020-02-01 02:48:13\n",
       "275     20200131      美国              6  2020-01-31 07:17:36\n",
       "276     20200127      美国              5  2020-01-27 17:20:43"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pro.ncov_global(country='美国', fields='country,publish_date,confirmed_num,update_time')\n",
    "df.tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date</th>\n",
       "      <th>title</th>\n",
       "      <th>content</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>20211120</td>\n",
       "      <td>“一带一路”建设高质量推进 中国方案惠及世界</td>\n",
       "      <td>2013年秋天，习近平主席访问哈萨克斯坦、印度尼西亚期间，先后提出共同建设“丝绸之路经济带”...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20211120</td>\n",
       "      <td>高标准 可持续 惠民生 推动共建“一带一路”高质量发展——习近平总书记在第三次“一带一路”建...</td>\n",
       "      <td>习近平总书记在第三次“一带一路”建设座谈会上发表的重要讲话，在与会代表中引起热烈反响。与会代...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>20211120</td>\n",
       "      <td>央视快评：推动共建“一带一路”高质量发展不断取得新成效</td>\n",
       "      <td>本台今天（11月20日）播发央视快评《推动共建“一带一路”高质量发展不断取得新成效》。</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>20211120</td>\n",
       "      <td>党的十九届六中全会在中管企业 中管金融企业 中管高校干部职工中引起热烈反响</td>\n",
       "      <td>党的十九届六中全会全面总结党的百年奋斗重大成就和历史经验，汇聚起坚定的历史自信和创造历史伟业...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>20211120</td>\n",
       "      <td>人民日报评论员文章：锚定既定奋斗目标 意气风发走向未来——论学习贯彻党的十九届六中全会精神</td>\n",
       "      <td>今天（11月20日）出版的人民日报发表评论员文章，题目是《锚定既定奋斗目标 意气风发走向未来...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       date                                              title  \\\n",
       "0  20211120                             “一带一路”建设高质量推进 中国方案惠及世界   \n",
       "1  20211120  高标准 可持续 惠民生 推动共建“一带一路”高质量发展——习近平总书记在第三次“一带一路”建...   \n",
       "2  20211120                        央视快评：推动共建“一带一路”高质量发展不断取得新成效   \n",
       "3  20211120              党的十九届六中全会在中管企业 中管金融企业 中管高校干部职工中引起热烈反响   \n",
       "4  20211120      人民日报评论员文章：锚定既定奋斗目标 意气风发走向未来——论学习贯彻党的十九届六中全会精神   \n",
       "\n",
       "                                             content  \n",
       "0  2013年秋天，习近平主席访问哈萨克斯坦、印度尼西亚期间，先后提出共同建设“丝绸之路经济带”...  \n",
       "1  习近平总书记在第三次“一带一路”建设座谈会上发表的重要讲话，在与会代表中引起热烈反响。与会代...  \n",
       "2        本台今天（11月20日）播发央视快评《推动共建“一带一路”高质量发展不断取得新成效》。  \n",
       "3  党的十九届六中全会全面总结党的百年奋斗重大成就和历史经验，汇聚起坚定的历史自信和创造历史伟业...  \n",
       "4  今天（11月20日）出版的人民日报发表评论员文章，题目是《锚定既定奋斗目标 意气风发走向未来...  "
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pro.cctv_news(date='20211120')\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ts_code</th>\n",
       "      <th>trade_date</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>pre_close</th>\n",
       "      <th>change</th>\n",
       "      <th>pct_chg</th>\n",
       "      <th>vol</th>\n",
       "      <th>amount</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>20201105</td>\n",
       "      <td>18.37</td>\n",
       "      <td>18.50</td>\n",
       "      <td>17.54</td>\n",
       "      <td>17.70</td>\n",
       "      <td>18.32</td>\n",
       "      <td>-0.62</td>\n",
       "      <td>-3.3843</td>\n",
       "      <td>1429469.44</td>\n",
       "      <td>2558562.453</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>20201104</td>\n",
       "      <td>18.35</td>\n",
       "      <td>18.48</td>\n",
       "      <td>17.96</td>\n",
       "      <td>18.32</td>\n",
       "      <td>17.96</td>\n",
       "      <td>0.36</td>\n",
       "      <td>2.0045</td>\n",
       "      <td>1247636.40</td>\n",
       "      <td>2275824.963</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>20201103</td>\n",
       "      <td>17.71</td>\n",
       "      <td>18.34</td>\n",
       "      <td>17.70</td>\n",
       "      <td>17.96</td>\n",
       "      <td>17.63</td>\n",
       "      <td>0.33</td>\n",
       "      <td>1.8718</td>\n",
       "      <td>957868.63</td>\n",
       "      <td>1727488.481</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>20201102</td>\n",
       "      <td>17.65</td>\n",
       "      <td>18.05</td>\n",
       "      <td>17.33</td>\n",
       "      <td>17.63</td>\n",
       "      <td>17.75</td>\n",
       "      <td>-0.12</td>\n",
       "      <td>-0.6761</td>\n",
       "      <td>968452.77</td>\n",
       "      <td>1702741.437</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>20201030</td>\n",
       "      <td>17.74</td>\n",
       "      <td>18.36</td>\n",
       "      <td>17.60</td>\n",
       "      <td>17.75</td>\n",
       "      <td>17.77</td>\n",
       "      <td>-0.02</td>\n",
       "      <td>-0.1125</td>\n",
       "      <td>1007803.83</td>\n",
       "      <td>1813064.343</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ts_code trade_date   open   high    low  close  pre_close  change  \\\n",
       "0  000001.SZ   20201105  18.37  18.50  17.54  17.70      18.32   -0.62   \n",
       "1  000001.SZ   20201104  18.35  18.48  17.96  18.32      17.96    0.36   \n",
       "2  000001.SZ   20201103  17.71  18.34  17.70  17.96      17.63    0.33   \n",
       "3  000001.SZ   20201102  17.65  18.05  17.33  17.63      17.75   -0.12   \n",
       "4  000001.SZ   20201030  17.74  18.36  17.60  17.75      17.77   -0.02   \n",
       "\n",
       "   pct_chg         vol       amount  \n",
       "0  -3.3843  1429469.44  2558562.453  \n",
       "1   2.0045  1247636.40  2275824.963  \n",
       "2   1.8718   957868.63  1727488.481  \n",
       "3  -0.6761   968452.77  1702741.437  \n",
       "4  -0.1125  1007803.83  1813064.343  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pro.daily(ts_code='000001.SZ', start_date='20200701', end_date='20201105')\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>index_code</th>\n",
       "      <th>industry_name</th>\n",
       "      <th>level</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>801020.SI</td>\n",
       "      <td>采掘</td>\n",
       "      <td>L1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>801030.SI</td>\n",
       "      <td>化工</td>\n",
       "      <td>L1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>801040.SI</td>\n",
       "      <td>钢铁</td>\n",
       "      <td>L1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>801050.SI</td>\n",
       "      <td>有色金属</td>\n",
       "      <td>L1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>801710.SI</td>\n",
       "      <td>建筑材料</td>\n",
       "      <td>L1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>801720.SI</td>\n",
       "      <td>建筑装饰</td>\n",
       "      <td>L1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>801730.SI</td>\n",
       "      <td>电气设备</td>\n",
       "      <td>L1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>801890.SI</td>\n",
       "      <td>机械设备</td>\n",
       "      <td>L1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>801740.SI</td>\n",
       "      <td>国防军工</td>\n",
       "      <td>L1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>801880.SI</td>\n",
       "      <td>汽车</td>\n",
       "      <td>L1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>801110.SI</td>\n",
       "      <td>家用电器</td>\n",
       "      <td>L1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>801130.SI</td>\n",
       "      <td>纺织服装</td>\n",
       "      <td>L1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>801140.SI</td>\n",
       "      <td>轻工制造</td>\n",
       "      <td>L1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>801200.SI</td>\n",
       "      <td>商业贸易</td>\n",
       "      <td>L1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>801010.SI</td>\n",
       "      <td>农林牧渔</td>\n",
       "      <td>L1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>801120.SI</td>\n",
       "      <td>食品饮料</td>\n",
       "      <td>L1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>801210.SI</td>\n",
       "      <td>休闲服务</td>\n",
       "      <td>L1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>801150.SI</td>\n",
       "      <td>医药生物</td>\n",
       "      <td>L1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>801160.SI</td>\n",
       "      <td>公用事业</td>\n",
       "      <td>L1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>801170.SI</td>\n",
       "      <td>交通运输</td>\n",
       "      <td>L1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>801180.SI</td>\n",
       "      <td>房地产</td>\n",
       "      <td>L1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>801080.SI</td>\n",
       "      <td>电子</td>\n",
       "      <td>L1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>801750.SI</td>\n",
       "      <td>计算机</td>\n",
       "      <td>L1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>801760.SI</td>\n",
       "      <td>传媒</td>\n",
       "      <td>L1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>801770.SI</td>\n",
       "      <td>通信</td>\n",
       "      <td>L1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>801780.SI</td>\n",
       "      <td>银行</td>\n",
       "      <td>L1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>801790.SI</td>\n",
       "      <td>非银金融</td>\n",
       "      <td>L1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>801230.SI</td>\n",
       "      <td>综合</td>\n",
       "      <td>L1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   index_code industry_name level\n",
       "0   801020.SI            采掘    L1\n",
       "1   801030.SI            化工    L1\n",
       "2   801040.SI            钢铁    L1\n",
       "3   801050.SI          有色金属    L1\n",
       "4   801710.SI          建筑材料    L1\n",
       "5   801720.SI          建筑装饰    L1\n",
       "6   801730.SI          电气设备    L1\n",
       "7   801890.SI          机械设备    L1\n",
       "8   801740.SI          国防军工    L1\n",
       "9   801880.SI            汽车    L1\n",
       "10  801110.SI          家用电器    L1\n",
       "11  801130.SI          纺织服装    L1\n",
       "12  801140.SI          轻工制造    L1\n",
       "13  801200.SI          商业贸易    L1\n",
       "14  801010.SI          农林牧渔    L1\n",
       "15  801120.SI          食品饮料    L1\n",
       "16  801210.SI          休闲服务    L1\n",
       "17  801150.SI          医药生物    L1\n",
       "18  801160.SI          公用事业    L1\n",
       "19  801170.SI          交通运输    L1\n",
       "20  801180.SI           房地产    L1\n",
       "21  801080.SI            电子    L1\n",
       "22  801750.SI           计算机    L1\n",
       "23  801760.SI            传媒    L1\n",
       "24  801770.SI            通信    L1\n",
       "25  801780.SI            银行    L1\n",
       "26  801790.SI          非银金融    L1\n",
       "27  801230.SI            综合    L1"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#获取申万一级行业列表\n",
    "df = pro.index_classify(level='L1', src='SW')\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ts_code</th>\n",
       "      <th>symbol</th>\n",
       "      <th>name</th>\n",
       "      <th>area</th>\n",
       "      <th>industry</th>\n",
       "      <th>list_date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>000001</td>\n",
       "      <td>平安银行</td>\n",
       "      <td>深圳</td>\n",
       "      <td>银行</td>\n",
       "      <td>19910403</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>000002.SZ</td>\n",
       "      <td>000002</td>\n",
       "      <td>万科A</td>\n",
       "      <td>深圳</td>\n",
       "      <td>全国地产</td>\n",
       "      <td>19910129</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000004.SZ</td>\n",
       "      <td>000004</td>\n",
       "      <td>国农科技</td>\n",
       "      <td>深圳</td>\n",
       "      <td>互联网</td>\n",
       "      <td>19910114</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000005.SZ</td>\n",
       "      <td>000005</td>\n",
       "      <td>世纪星源</td>\n",
       "      <td>深圳</td>\n",
       "      <td>环境保护</td>\n",
       "      <td>19901210</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>000006.SZ</td>\n",
       "      <td>000006</td>\n",
       "      <td>深振业A</td>\n",
       "      <td>深圳</td>\n",
       "      <td>区域地产</td>\n",
       "      <td>19920427</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ts_code  symbol  name area industry list_date\n",
       "0  000001.SZ  000001  平安银行   深圳       银行  19910403\n",
       "1  000002.SZ  000002   万科A   深圳     全国地产  19910129\n",
       "2  000004.SZ  000004  国农科技   深圳      互联网  19910114\n",
       "3  000005.SZ  000005  世纪星源   深圳     环境保护  19901210\n",
       "4  000006.SZ  000006  深振业A   深圳     区域地产  19920427"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = pro.query('stock_basic', exchange='', list_status='L', fields='ts_code,symbol,name,area,industry,list_date')\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Homework\n",
    "\n",
    "1. 取得10家市值最大的**银行行业**的上市公司从去年年初至今的股票的日行情数据，并将该数据存入MySQL数据库\n",
    "\n",
    "2. 动量效应指的是指股票的收益率有延续原来的运动方向的趋势，即过去一段时间收益率较高的股票在未来获得的收益率仍会高于过去收益率较低的股票。请用调用数据去验证，如随机寻找部分的涨停股票，考察其涨停后几日的发展趋势，并和其他股票进行对比。\n",
    "\n",
    "3. 有人说持有低市值股票可以获利，请试试是否正确。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### OECD\n",
    "\n",
    "https://stats.oecd.org/\n",
    "\n",
    "The OECD has application programming interfaces (APIs) that provide access to datasets in the catalogue of OECD databases.\n",
    "\n",
    "Please see the instruction of API as follows\n",
    "\n",
    "https://data.oecd.org/api/sdmx-json-documentation/\n",
    "\n",
    "你是否可以取到其中的数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
